package net.upload;

import java.io.IOException;

import net.connection.Connection;
import net.connection.ConnectionManagerFactory;
import net.peer.Peer;
import net.protocol.ProtocolFactory;

public class Upload implements Runnable{
	private Object data;
	private Connection connection;
	private Peer peer;
	
	
	public Upload(Object data, Connection connection, Peer peer) {
		this.data = data;
		this.connection = connection;
		this.peer = peer;
	}
	
	@Override
	public void run(){
		try {
			ProtocolFactory.getProtocol().sendData(connection.getSocket().getOutputStream(), data);
		} catch (IOException e) {
			e.printStackTrace();
		} finally{
			ConnectionManagerFactory.getManager().closeConnection(peer,connection);
		}
	}
	
	
}
